package logic

import (
	"context"
	"month/rpc/monthclient"

	"month/api/internal/svc"
	"month/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HistoryFindLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHistoryFindLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HistoryFindLogic {
	return &HistoryFindLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HistoryFindLogic) HistoryFind(req *types.HistoryFindRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	commitId := req.CommitId
	commitText := req.CommitText

	d, err := l.svcCtx.MonthRpc.HistoryFind(l.ctx, &monthclient.HistoryFindRequest{
		CommitId:   commitId,
		CommitText: commitText,
	})

	return &types.Response{
		Code:    d.Code,
		Message: d.Message,
		Data:    d.Data,
	}, err
}
